<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>个人中心 - 管理你的资料</title>
    <link rel="stylesheet" href="css/style.css">
    <style>
        .profile-container {
            max-width: 600px;
            margin: 50px auto;
            background: white;
            padding: 30px;
            border-radius: 12px;
            box-shadow: 0 5px 15px rgba(0, 0, 0, 0.05);
        }
        .profile-header {
            display: flex;
            align-items: center;
            gap: 20px;
            margin-bottom: 30px;
            padding-bottom: 20px;
            border-bottom: 1px solid #eee;
        }
        .profile-avatar {
            width: 120px;
            height: 120px;
            border-radius: 50%;
            background: #f0f0f0;
            display: flex;
            align-items: center;
            justify-content: center;
            font-size: 2rem;
            color: #666;
            cursor: pointer;
            position: relative;
            overflow: hidden;
        }
        .profile-avatar img {
            width: 100%;
            height: 100%;
            object-fit: cover;
        }
        .profile-avatar input {
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            opacity: 0;
            cursor: pointer;
        }
        .profile-info h2 {
            margin: 0;
        }
        .profile-info p {
            margin: 5px 0;
            color: #666;
        }
        .form-group {
            margin-bottom: 20px;
        }
        .form-group label {
            display: block;
            margin-bottom: 8px;
            font-weight: 500;
        }
        .form-group input, .form-group textarea {
            width: 100%;
            padding: 12px;
            border: 1px solid #ddd;
            border-radius: 6px;
            font-size: 1rem;
        }
        .update-success {
            color: #2ecc71;
            padding: 10px;
            background: #e8f5e9;
            border-radius: 6px;
            margin-bottom: 20px;
        }
        .update-error {
            color: #e74c3c;
            padding: 10px;
            background: #fcebeb;
            border-radius: 6px;
            margin-bottom: 20px;
        }
        .action-buttons {
            display: flex;
            gap: 15px;
            margin-top: 30px;
        }
        .file-upload-info {
            font-size: 0.9rem;
            color: #666;
            margin-top: 5px;
        }
    </style>
</head>
<body>
<div class="profile-container">
    <c:if test="${empty sessionScope.username}">
        <p style="text-align: center; color: #e74c3c;">请先登录才能访问个人中心</p>
        <p style="text-align: center; margin-top: 20px;"><a href="login.jsp" class="btn">立即登录</a></p>
    </c:if>

    <c:if test="${not empty sessionScope.username}">
        <div class="profile-header">
            <div class="profile-avatar">
                <c:if test="${not empty user.avatar}">
                    <img src="${user.avatar}" alt="用户头像">
                </c:if>
                <c:if test="${empty user.avatar}">
                    <i class="fas fa-user"></i>
                </c:if>
                <input type="file" id="avatarFile" name="avatarFile" accept="image/*">
            </div>
            <div class="profile-info">
                <h2>${sessionScope.username}</h2>
                <p>注册时间：${user.createdAt}</p>
                <p>用户角色：<c:if test="${user.role == 1}">普通用户</c:if><c:if test="${user.role == 2}">管理员</c:if></p>
            </div>
        </div>

        <c:if test="${not empty requestScope.updateSuccess}">
            <div class="update-success">
                    ${requestScope.updateSuccess}
            </div>
        </c:if>
        <c:if test="${not empty requestScope.updateError}">
            <div class="update-error">
                    ${requestScope.updateError}
            </div>
        </c:if>

        <form action="ProfileServlet" method="post" enctype="multipart/form-data">
            <div class="form-group">
                <label for="email">邮箱</label>
                <input type="email" id="email" name="email" value="${user.email}" placeholder="请输入邮箱">
            </div>

            <div class="form-group">
                <label for="avatar">头像上传</label>
                <div class="file-upload-info">支持JPG、PNG等图片格式，文件大小不超过2MB</div>
                <input type="file" id="avatarFileForm" name="avatarFile" accept="image/*">
            </div>

<%--            <div class="form-group">--%>
<%--                <label for="signature">个人签名</label>--%>
<%--                <textarea id="signature" name="signature" rows="3">${user.signature}</textarea>--%>
<%--            </div>--%>

            <div class="action-buttons">
                <button type="submit" class="btn">保存修改</button>
                <a href="index.jsp" class="btn" style="background: #4a90e2;">返回首页</a>
                <a href="logout" class="btn" style="background: #e74c3c;">注销登录</a>
            </div>
        </form>
    </c:if>
</div>
</body>
</html>